class Circle { private int R; private static double Pi=3.14; public void area() { double a=Pi*R*R; System.out.println("Area is "+a); } public Circle(int n) { R=n; } } class demo { public static void main(String args[]) { Circle a=new Circle(5); Circle b=new Circle(3); Circle c=new Circle(2); a.area(); b.area(); c.area(); } }
Area is 78.5 Area is 28.26 Area is 12.56
class Account { private int accno,balance; private static double irate=10.25; public void interest(int n) { double si=balance*irate*n/100; System.out.println("Interest is "+si); } public Account(int an,int bl) { accno=an; balance=bl; } } class demo { public static void main(String args[]) { Account a=new Account(4117,25000); Account b=new Account(3012,10000); a.interest(5); b.interest(2); } }
Interest is 12812.5 Interest is 2050.0
class Student { private int rollno; private String name; public static int count; public void showData() { System.out.print("RollNo is "+rollno); System.out.println("Name is "+name); } public Student(int r,String n) { rollno=r; name=n; count=count+1; } } class demo { public static void main(String args[]) { System.out.println("Total Students: "+Student.count); Student a=new Student(4117,"Amit Jain"); Student b=new Student(3012,"Seeta Rathi"); System.out.println("Total Students:"+Student.count); Student c=new Student(5123,"Raja Rao"); System.out.println("Total Students:"+Student.count); a.showData(); b.showData(); c.showData(); } }
Total Students: 0 Total Students: 2 Total Students: 3 RollNo is 4117 Name is Amit Jain RollNo is 3012 Name is Seeta Rathi RollNo is 5123 Name is Raja Rao